package com.pluszg.nutrition.account.controller;

import com.pluszg.nutrition.account.service.AccountService;
import com.pluszg.nutrition.api.controller.account.AccountController;
import com.pluszg.nutrition.model.account.Account;
import com.pluszg.nutrition.common.resp.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;


@RestController
public class AccountControllerImpl implements AccountController {

    @Autowired
    private AccountService accountService;

    @Override
    public CommonResponse<Account> add(@RequestBody Account account) {
        return new CommonResponse<>(accountService.add(account));
    }

    @Override
    public CommonResponse<Account> findById(@PathVariable("id")  String id) {
        return new CommonResponse<>(accountService.findById(id));
    }

    @Override
    public CommonResponse<Account> modify(@RequestBody Account account) {
        return new CommonResponse<>(accountService.modify(account));
    }

    @Override
    public CommonResponse<Boolean> delete(@RequestParam("id") String id) {
        return new CommonResponse<>(accountService.delete(id));
    }

    @Override
    public CommonResponse<Void> reduceAccount (@RequestParam("id") String id,@RequestParam("amount") BigDecimal amount) {
        accountService.reduceAccount(id, amount);
        return new CommonResponse<>();
    }
}
